package com.example.project.controller.project;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.project.annotation.Log;
import com.example.project.core.controller.BaseController;
import com.example.project.core.domain.AjaxResult;
import com.example.project.core.page.TableDataInfo;
import com.example.project.entity.IssueStatus;
import com.example.project.enums.BusinessType;
import com.example.project.service.IssueStatusService;
import com.example.project.utils.poi.ExcelUtil;

/**
 * 问题状态，定义问题的可能状态Controller
 * 
 * @author ruoyi
 * @date 2025-09-23
 */
@Controller
@RequestMapping("/project/statuse")
public class IssueStatusController extends BaseController {

	private String prefix = "pm/statuse";

	@Autowired
	private IssueStatusService issueStatusService;

	@RequiresPermissions("project:statuse:view")
	@GetMapping()
	public String statuse() {
		return prefix + "/statuse";
	}

	/**
	 * 查询问题状态，定义问题的可能状态列表
	 */
	@RequiresPermissions("project:statuse:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IssueStatus tIssueStatus) {
		startPage();
		List<IssueStatus> list = issueStatusService.selectIssueStatusList(tIssueStatus);
		return getDataTable(list);
	}

	/**
	 * 导出问题状态，定义问题的可能状态列表
	 */
	@RequiresPermissions("project:statuse:export")
	@Log(title = "问题状态，定义问题的可能状态", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(IssueStatus tIssueStatus) {
		List<IssueStatus> list = issueStatusService.selectIssueStatusList(tIssueStatus);
		ExcelUtil<IssueStatus> util = new ExcelUtil<IssueStatus>(IssueStatus.class);
		return util.exportExcel(list, "问题状态，定义问题的可能状态数据");
	}

	/**
	 * 新增问题状态，定义问题的可能状态
	 */
	@RequiresPermissions("project:statuse:add")
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存问题状态，定义问题的可能状态
	 */
	@RequiresPermissions("project:statuse:add")
	@Log(title = "问题状态，定义问题的可能状态", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IssueStatus tIssueStatus) {
		return toAjax(issueStatusService.insertIssueStatus(tIssueStatus));
	}

	/**
	 * 修改问题状态，定义问题的可能状态
	 */
	@RequiresPermissions("project:statuse:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		IssueStatus issueStatus = issueStatusService.selectIssueStatusById(id);
		mmap.put("issueStatus", issueStatus);
		return prefix + "/edit";
	}

	/**
	 * 修改保存问题状态，定义问题的可能状态
	 */
	@RequiresPermissions("project:statuse:edit")
	@Log(title = "问题状态，定义问题的可能状态", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IssueStatus tIssueStatus) {
		return toAjax(issueStatusService.updateIssueStatus(tIssueStatus));
	}

	/**
	 * 删除问题状态，定义问题的可能状态
	 */
	@RequiresPermissions("project:statuse:remove")
	@Log(title = "问题状态，定义问题的可能状态", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(issueStatusService.deleteIssueStatusByIds(ids));
	}
}
